/*
 * $Id: Hashable.h,v 1.1 2005-04-17 16:18:45 bacon Exp $
 */

#ifndef _XPP_HASHABLE_CLASS_
#define _XPP_HASHABLE_CLASS_

#include <xp/types.h>
#include <xp/macros.h>

namespace xpp 
{

	class Hashable
	{
	public:
		virtual ~Hashable () {}

		virtual xp_size_t hashCode () const = 0;

		static xp_size_t hashCode (const void* data, xp_size_t size)
		{
			xp_size_t n = 0;
			xp_byte_t* p = (xp_byte_t*)data;
	
			/*
			for (xp_size_t i = 0; i < size; i++) {
				n <<= 1;
				n += *p++;
			}
			*/
	
			for (xp_size_t i = 0; i < size; i++) n = n * 31 + *p++;
	
			/*
			for (xp_size_t i = 0; i < size; i++) {
				n = (n << 4) + *p++;
				//xp_size_t g = n & 0xF0000000U;
				xp_size_t g = n & ((xp_size_t)0xF << (xp_sizeof(xp_size_t) * 8 - 4));
				n &= ~g;
			}
			*/
	
			return n;
		}

	};

}

#endif
